package com.musicalevents.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.sql.JoinType;

import com.musicalevents.dao.EventDAO;
import com.musicalevents.entity.Event;


@SuppressWarnings("unchecked")
public class EventDAOImpl extends GenericDAOImpl<Event, Integer> implements EventDAO {

	public EventDAOImpl(Class<Event> type) {
		super(type);
	}

	public List<Event> fetchAllEventsLinkPlace() {
		
		Criteria crit = getSession().createCriteria(Event.class);
		crit.createAlias("place", "p", JoinType.INNER_JOIN);
		List<Event> events = crit.list();
		return (events);
	}

	public List<Event> fetchAllEventsLinkPlaceTown() {
		
		Criteria crit = getSession().createCriteria(Event.class);
		crit.createAlias("place", "p", JoinType.INNER_JOIN);
		crit.createAlias("p.town", "t", JoinType.INNER_JOIN);
		List<Event> events = crit.list();
		return (events);
	}

}
